<?php



class Site
{
    static $lastpage = "";
    static $defaultmodule = "images";

    static function Init()
    {
        Route::Init(Site::$defaultmodule);
        User::Init();

        Renderer::RegisterScript("jquery-1.4.2.min.js");
        Renderer::RegisterScript("pictorater.js");
       // Renderer::RegisterScript("jquery.uploadify.v2.1.0.min.js");
      //  Renderer::RegisterScript("swfobject.js");
        Renderer::RegisterStyle("styles.css");
       // Renderer::RegisterStyle("uploadify.css");

        Renderer::$var["site_title"] = "Pictorater — Image hosting dinosaur";

        $module = Site::GetModule(Route::$module);
        $module->process();
    }

    static function GetModule($modulename)
    {
        $path = Context::$request["rootdir"].DIR_SEPARATOR.MODULE_FOLDER.DIR_SEPARATOR.strtolower($modulename).DIR_SEPARATOR.MODULE_MAINFILE;
        if(file_exists($path))
        {
            require $path;
            if(class_exists(ucfirst($modulename)))
                return new $modulename();
            else
                ErrorHandler::RaiseFatal("Module class not found.");
        }
        else
        {
            echo $path;
            ErrorHandler::RaiseFatal("Module not found.");
        }

    }


    static function SetLastPage($link = "")
    {
        $link == '' ? $link = Context::$request["url"] : null;
        Site::$lastpage = $link;
        Context::$session["lastpage"] = $link;
    }

    static function Redirect($link = "", $replace = null, $code = 302)
    {
        $link == '' ? $link = Context::$request["url"] : null;
        Header("Location: ".$link, $replace, $code);
        die;
    }
}

?>